package cn.edu.just.firstjavaapp.l22;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class MouseListenerDemo01 extends JFrame implements MouseListener , MouseMotionListener {
    public static void main(String[] args) {
        MouseListenerDemo01 mouseListenerDemo01 = new MouseListenerDemo01();
        mouseListenerDemo01.setSize(500,300);
        mouseListenerDemo01.setLocation(10,10);
        mouseListenerDemo01.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mouseListenerDemo01.setVisible(true);
        mouseListenerDemo01.addMouseListener(mouseListenerDemo01);
        mouseListenerDemo01.addMouseMotionListener(mouseListenerDemo01);

        MouseAdapter mouseAdapter = new MouseAdapter(){
            @Override
            public void mouseClicked(MouseEvent e) {
                System.out.println("mouse clicked at ("+e.getX()+","+e.getY()+")");
            }
        };


    }

    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("mouse clicked at ("+e.getX()+","+e.getY()+")");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("mouse pressed at ("+e.getX()+","+e.getY()+")");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("mouse released at ("+e.getX()+","+e.getY()+")");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        this.getContentPane().setBackground(new Color(255,0,0));
    }

    @Override
    public void mouseExited(MouseEvent e) {
        this.getContentPane().setBackground(new Color(255,255,0));
    }

    @Override
    public void mouseDragged(MouseEvent e) {
        System.out.println("mouse dragged at "+e.getX()+","+e.getY());
    }

    @Override
    public void mouseMoved(MouseEvent e) {
        System.out.println("mouse move at "+e.getX()+","+e.getY());
    }
}
